package com.sunny.wordstudy;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.media.AudioManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import com.sunny.dict.MDict;
import com.sunny.wordstudy.lib.Stat;
import com.sunny.wordstudy.lib.Study;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.Locale;

public class DictView extends Activity
  implements TextWatcher, ah
{
  static final int[] s;
  private View.OnClickListener A;
  private View.OnClickListener B;
  private View.OnClickListener C;
  Stat a = Stat.a();
  Study b = Study.a();
  String c = "file:///android_asset/fonts/test.html";
  String d = "<table width='%1$s' border='0'><tr><td align='center' bgcolor='#CECECE'><h2><font color='#ff1050'>%2$s</font></h2></td></tr></table><center><font color='#1b6fb4'>(with MDict support)</font><hr style='border:1px dashed gray;height:1px'>%3$s";
  ArrayAdapter e;
  AutoCompleteTextView f;
  Button g;
  Button h;
  TextView i;
  Button j;
  int k = -1;
  String[] l;
  String m;
  TextView n;
  TextView o;
  TextView p;
  TextView q;
  WebView r;
  private bk t = null;
  private final String u = "lastusedict";
  private final int v;
  private final int w;
  private final int x;
  private final int y;
  private final int z;

  static
  {
    int[] arrayOfInt = new int[12];
    arrayOfInt[0] = -16777216;
    arrayOfInt[1] = -16776961;
    arrayOfInt[2] = -16711681;
    arrayOfInt[3] = -12303292;
    arrayOfInt[4] = -7829368;
    arrayOfInt[5] = -16711936;
    arrayOfInt[6] = -3355444;
    arrayOfInt[7] = -65281;
    arrayOfInt[8] = -65536;
    arrayOfInt[9] = -1;
    arrayOfInt[11] = -256;
    s = arrayOfInt;
  }

  public DictView()
  {
    String[] arrayOfString = new String[1];
    arrayOfString[0] = "test";
    this.l = arrayOfString;
    this.m = "";
    this.v = 0;
    this.w = 1;
    this.x = 2;
    this.y = 3;
    this.z = 1001;
    this.A = new g(this);
    this.B = new h(this);
    this.C = new i(this);
  }

  private static int a(String paramString, int paramInt)
  {
    int i1 = Integer.parseInt(paramString);
    if (i1 == 0)
      i1 = paramInt;
    return i1;
  }

  private static String a(String paramString1, String paramString2, String paramString3)
  {
    String str3;
    if (paramString1.length() == 0)
    {
      str3 = "";
      return str3;
    }
    String str1 = "";
    int i1;
    for (String str2 = paramString1; ; str2 = str2.substring(i1 + paramString2.length(), str2.length()))
    {
      do
      {
        if (str2.indexOf(paramString2) == -1)
          str3 = str1 + str2;
        i1 = str2.indexOf(paramString2);
      }
      while (i1 == str2.length());
      str1 = str1 + str2.substring(0, i1) + paramString3;
    }
  }

  private void a(int paramInt)
  {
    SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (paramInt == 0)
    {
      int i3 = localSharedPreferences.getInt("soundvolume", 11);
      if (i3 == 11)
        i3 = 5;
      this.b.a(i3, false);
    }
    while (true)
    {
      return;
      int i1 = paramInt + this.b.b();
      this.b.a(i1, true);
      int i2 = this.b.b();
      SharedPreferences.Editor localEditor = localSharedPreferences.edit();
      localEditor.putInt("soundvolume", i2);
      localEditor.commit();
    }
  }

  private void a(String paramString)
  {
    label71: String str8;
    if ((MDict.getDictCount() > this.k) && (this.k >= 0))
    {
      a(true);
      if (paramString.equals(""))
      {
        String str13 = MDict.getDictDesc(this.k);
        this.r.getSettings().setDefaultTextEncodingName("UTF-8");
        this.r.loadDataWithBaseURL(this.c, str13, "text/html", "UTF-8", "");
        return;
      }
      int i1 = MDict.getNearestKeywordID(this.k, paramString);
      str8 = MDict.getKeywordByID(this.k, i1);
      if (!(paramString.equals(str8)))
        break label705;
    }
    for (String str9 = MDict.a(this.k, str8); ; str9 = "")
    {
      StringBuilder localStringBuilder;
      int i2;
      int i3;
      int i4;
      if (str9.length() == 0)
      {
        localStringBuilder = new StringBuilder();
        if (this.k >= 0)
        {
          i2 = MDict.getNearestKeywordID(this.k, paramString);
          i3 = MDict.getDictDataCount(this.k);
          String str11 = getResources().getString(2131099652);
          Object[] arrayOfObject3 = new Object[1];
          arrayOfObject3[0] = paramString;
          localStringBuilder.append(String.format(str11, arrayOfObject3)).append("<br/>");
          i4 = 0;
          label201: if (i4 < 20)
            break label252;
        }
      }
      for (String str10 = MDict.b(localStringBuilder.toString()); ; str10 = MDict.b(str9))
      {
        this.r.getSettings().setDefaultTextEncodingName("UTF-8");
        this.r.loadDataWithBaseURL(this.c, str10, "text/html", "UTF-8", "");
        break label71:
        if (i2 + i4 < i3)
        {
          label252: String str12 = MDict.getKeywordByID(this.k, i2 + i4);
          localStringBuilder.append("<b> ").append(i4 + 1).append(". </b> ").append("<a href=\"entry://").append(str12).append("\">").append(str12).append("</a><br/>");
        }
        ++i4;
        break label201:
      }
      if (paramString.equals(""))
        d();
      a(false);
      String str1 = "";
      if (this.a.isLoadedDict())
        str1 = this.a.getDictWordMean(paramString);
      if (str1.length() > 0)
      {
        this.n.setText(paramString);
        this.p.setText(str1);
        this.o.setText("  " + this.a.getDictWordVoice(paramString));
        String str6 = this.a.getDictWordSample(paramString);
        if (str6.length() == 0);
        for (String str7 = getResources().getString(2131099837); ; str7 = a(a(str6, paramString, "<strong><font color=\"blue\">" + paramString + "</font></strong>"), "\n", "<br/>"))
        {
          this.q.setText(Html.fromHtml(str7));
          break label71:
        }
      }
      String str5;
      Object[] arrayOfObject2;
      if ("".trim().length() == 0)
      {
        str5 = getResources().getString(2131099653);
        arrayOfObject2 = new Object[1];
        arrayOfObject2[0] = paramString;
      }
      String str2;
      Object[] arrayOfObject1;
      for (String str3 = String.format(str5, arrayOfObject2) + "<br/>"; ; str3 = new StringBuilder(String.valueOf(String.format(str2, arrayOfObject1))).append("<br/>").toString() + "")
      {
        a(true);
        String str4 = MDict.b(str3);
        this.r.getSettings().setDefaultTextEncodingName("UTF-8");
        this.r.loadDataWithBaseURL(this.c, str4, "text/html", "UTF-8", "");
        break label71:
        str2 = getResources().getString(2131099652);
        arrayOfObject1 = new Object[1];
        label705: arrayOfObject1[0] = paramString;
      }
    }
  }

  private void a(boolean paramBoolean)
  {
    if (paramBoolean)
    {
      this.r.setVisibility(0);
      this.n.setText("");
      this.n.setVisibility(4);
      this.p.setText("");
      this.p.setVisibility(4);
      this.o.setText("");
      this.o.setVisibility(4);
      this.q.setText("");
      this.q.setVisibility(4);
    }
    while (true)
    {
      return;
      this.r.loadDataWithBaseURL(this.c, "", "text/html", "UTF-8", "");
      this.r.setVisibility(4);
      this.n.setVisibility(0);
      this.p.setVisibility(0);
      this.o.setVisibility(0);
      this.q.setVisibility(0);
    }
  }

  private static int b(String paramString, int paramInt)
  {
    int i1 = Integer.parseInt(paramString);
    if (i1 == 0);
    for (i1 = paramInt; ; i1 = s[(i1 - 1)])
      do
        return i1;
      while ((i1 <= 0) || (i1 > 12));
  }

  private void b(String paramString)
  {
    int i1;
    label12: int i2;
    if (!(paramString.equals("dict.edb")))
    {
      i1 = 0;
      if (i1 >= MDict.getDictCount())
      {
        i2 = 0;
        if (i2 == 0)
        {
          if (MDict.getDictCount() <= 0)
            break label122;
          this.k = 0;
          MDict.getDictFileName(0);
        }
      }
    }
    while (true)
    {
      MDict.setMddsWithDictID(this.k);
      return;
      String str = MDict.getDictFileName(i1);
      if (str.equals(paramString))
      {
        this.k = i1;
        i2 = 1;
      }
      String[] arrayOfString = str.split("/");
      if ((arrayOfString.length > 0) && (arrayOfString[(arrayOfString.length - 1)].equals(paramString)))
      {
        this.k = i1;
        i2 = 1;
      }
      ++i1;
      break label12:
      label122: this.k = -1;
    }
  }

  private void d()
  {
    a(true);
    String str1 = getResources().getString(2131099761);
    String str2 = getResources().getString(2131099651);
    String str3 = this.d;
    Object[] arrayOfObject = new Object[3];
    arrayOfObject[0] = "100%";
    arrayOfObject[1] = str1;
    arrayOfObject[2] = str2;
    String str4 = String.format(str3, arrayOfObject);
    this.r.loadDataWithBaseURL(this.c, MDict.b(str4), "text/html", "UTF-8", "");
  }

  private void e()
  {
    String str1 = "dict.edb";
    String str2 = getString(2131099660);
    String str7;
    String str4;
    if ((MDict.getDictCount() > this.k) && (this.k >= 0))
    {
      str1 = MDict.getDictFileName(this.k);
      str2 = MDict.getDictTitle(this.k);
      if (MDict.a(str2))
        str2 = "";
      String[] arrayOfString = str1.split("/");
      if (arrayOfString.length > 0)
      {
        String str6 = arrayOfString[(arrayOfString.length - 1)];
        str7 = str2;
        str4 = str6;
      }
    }
    String str3;
    for (Object localObject = str7; ; localObject = str3)
    {
      TextView localTextView = this.i;
      String str5 = getResources().getString(2131099658);
      Object[] arrayOfObject = new Object[2];
      arrayOfObject[0] = str4;
      arrayOfObject[1] = localObject;
      localTextView.setText(Html.fromHtml(String.format(str5, arrayOfObject)));
      return;
      str3 = str2;
      str4 = str1;
    }
  }

  public final AudioManager a()
  {
    return ((AudioManager)getSystemService("audio"));
  }

  public void afterTextChanged(Editable paramEditable)
  {
    paramEditable.toString().length();
  }

  public final void b()
  {
    this.b.c();
  }

  public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
  {
  }

  public final void c()
  {
    if (this.t == null)
      return;
    this.t.a(this.m);
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    super.onActivityResult(paramInt1, paramInt2, paramIntent);
    this.b.a(null);
    this.b.a(this);
    if (paramInt1 != 1001)
      return;
    b(PreferenceManager.getDefaultSharedPreferences(this).getString("lastusedict", "dict.edb"));
    e();
    a("");
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903042);
    this.b.a(null);
    this.b.a(this);
    String str1 = "MDX COUNT:" + MDict.getDictCount() + "  MDD COUNT:" + MDict.getMddCount();
    System.out.print(str1);
    String str2 = "";
    if (getIntent() != null)
      str2 = getIntent().getStringExtra("word");
    if (str2 == null);
    for (String str3 = ""; ; str3 = str2)
    {
      setTitle(2131099761);
      this.e = new ArrayAdapter(this, 17367050, this.l);
      this.f = ((AutoCompleteTextView)findViewById(2131230727));
      this.f.setAdapter(this.e);
      this.f.addTextChangedListener(this);
      this.g = ((Button)findViewById(2131230728));
      this.g.setOnClickListener(this.A);
      this.h = ((Button)findViewById(2131230726));
      this.h.setOnClickListener(this.B);
      this.i = ((TextView)findViewById(2131230725));
      this.j = ((Button)findViewById(2131230729));
      this.j.setOnClickListener(this.C);
      this.n = ((TextView)findViewById(2131230731));
      this.o = ((TextView)findViewById(2131230732));
      this.p = ((TextView)findViewById(2131230733));
      this.q = ((TextView)findViewById(2131230734));
      this.r = ((WebView)findViewById(2131230730));
      this.r.getSettings().setDefaultTextEncodingName("UTF-8");
      this.r.setWebViewClient(new j(this));
      this.n.setText("");
      this.o.setText("");
      this.p.setText("");
      this.q.setText("");
      if (this.a.getDictLang().equals("en"))
      {
        Typeface localTypeface = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/WSEnVoice.ttf");
        this.o.setTypeface(localTypeface);
      }
      SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
      a(0);
      this.n.setTextSize(a(localSharedPreferences.getString("wordfontsize", "28"), 28));
      int i1 = b(localSharedPreferences.getString("wordfontcolor", "0"), -16776961);
      if (i1 != -1)
        this.n.setTextColor(i1);
      this.o.setTextSize(a(localSharedPreferences.getString("wordvoicefontsize", "18"), 18));
      int i2 = b(localSharedPreferences.getString("wordvoicefontcolor", "0"), -16711681);
      if (i2 != -1)
        this.o.setTextColor(i2);
      this.p.setTextSize(a(localSharedPreferences.getString("wordmeanfontsize", "24"), 24));
      int i3 = b(localSharedPreferences.getString("wordmeanfontcolor", "0"), -16711936);
      if (i3 != -1)
        this.p.setTextColor(i3);
      this.q.setTextSize(a(localSharedPreferences.getString("wordsamplefontsize", "18"), 18));
      int i4 = b(localSharedPreferences.getString("wordsamplefontcolor", "-1"), -1);
      if (i4 != -1)
        this.q.setTextColor(i4);
      String str4;
      Locale localLocale1;
      if (Stat.b > 0)
      {
        System.err.println("!!!!Begin TTS Create: Have TTS Installed");
        new Locale("EN");
        str4 = this.a.getStudyLang().toLowerCase();
        System.err.println("TTS study db lang " + str4);
        localLocale1 = Locale.US;
        if (!(str4.equals("en")))
          break label905;
      }
      for (Locale localLocale2 = Locale.US; ; localLocale2 = localLocale1)
      {
        label759: System.err.println("TTS use local " + localLocale2.toString());
        if ((0x1 & Stat.b) == 1)
        {
          System.err.println("!!!!Use TTS Extended Service");
          this.t = new bl(this, localLocale2);
          label818: b(localSharedPreferences.getString("lastusedict", "dict.edb"));
          if ((this.k == -1) && (!(this.a.isLoadedDict())) && (MDict.getDictCount() > 0))
          {
            this.k = 0;
            MDict.setMddsWithDictID(this.k);
          }
          e();
          if (str3.length() <= 0)
            break label1124;
          this.m = str3;
          this.f.setText(str3);
          a(str3);
        }
        while (true)
        {
          while (true)
          {
            return;
            if (str4.equals("fr"))
              label905: localLocale2 = Locale.FRENCH;
            if (str4.equals("de"))
              localLocale2 = Locale.GERMAN;
            if (str4.equals("es"))
              localLocale2 = new Locale("es");
            if (str4.equals("jp"))
              localLocale2 = Locale.JAPAN;
            if (str4.equals("kr"))
              localLocale2 = Locale.KOREAN;
            if (!(str4.equals("it")))
              break label1131;
            localLocale2 = Locale.ITALIAN;
            break label759:
            System.err.println("!!!!Use Default Google TTS Engine");
            try
            {
              Class localClass = getClassLoader().loadClass("com.sunny.wordstudy.TTSGoogle");
              Class[] arrayOfClass = new Class[2];
              arrayOfClass[0] = Context.class;
              arrayOfClass[1] = Locale.class;
              Method localMethod = localClass.getMethod("getGoogleTTS", arrayOfClass);
              Object[] arrayOfObject = new Object[2];
              arrayOfObject[0] = this;
              arrayOfObject[1] = localLocale2;
              this.t = ((bk)localMethod.invoke(null, arrayOfObject));
            }
            catch (Exception localException)
            {
              localException.printStackTrace();
            }
          }
          break label818:
          label1124: label1131: d();
        }
      }
    }
  }

  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    super.onCreateOptionsMenu(paramMenu);
    paramMenu.add(0, 0, 0, getResources().getString(2131099654));
    paramMenu.add(0, 1, 1, getResources().getString(2131099655));
    paramMenu.add(0, 2, 2, getResources().getString(2131099656));
    paramMenu.add(0, 3, 3, getResources().getString(2131099657));
    return true;
  }

  protected void onDestroy()
  {
    if (this.t != null)
      this.t.a();
    super.onDestroy();
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if (paramInt == 24)
      a(1);
    for (boolean bool = true; ; bool = super.onKeyDown(paramInt, paramKeyEvent))
      while (true)
      {
        return bool;
        if (paramInt != 25)
          break;
        a(-1);
        bool = true;
      }
  }

  public boolean onOptionsItemSelected(MenuItem paramMenuItem)
  {
    switch (paramMenuItem.getItemId())
    {
    default:
    case 0:
    case 1:
    case 2:
    case 3:
    }
    while (true)
    {
      label36: return true;
      startActivityForResult(new Intent(this, ChooseDictView.class), 1001);
      continue;
      if (this.k >= 0)
      {
        String str = MDict.getDictFileName(this.k);
        MDict.refreshDictList();
        int i1 = MDict.getDictIDByFileName(str);
        if (i1 == this.k)
          continue;
        if (i1 >= 0)
        {
          this.k = i1;
          MDict.setMddsWithDictID(this.k);
        }
        if ((MDict.getDictCount() <= 1) && (((MDict.getDictCount() != 1) || (!(this.a.isLoadedDict())))));
        for (int i2 = 0; i2 != 0; i2 = 1)
        {
          this.k = (1 + this.k);
          if (MDict.getDictCount() == this.k)
            this.k = -1;
          if ((this.k == -1) && (!(this.a.isLoadedDict())))
            this.k = (1 + this.k);
          if (this.k >= 0)
            MDict.clearDictMemoryBuffer(this.k);
          MDict.setMddsWithDictID(this.k);
          e();
          a("");
          break label36:
        }
        if (MDict.getDictCount() != 0)
          continue;
        Stat.isLoadedVoice();
      }
      MDict.refreshDictList();
      continue;
      a("");
      continue;
      finish();
    }
  }

  public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
  {
  }
}

/* Location:           E:\Desktop\Android\wordstd\classes_dex2jar.jar
 * Qualified Name:     com.sunny.wordstudy.DictView
 * JD-Core Version:    0.5.3
 */